package 二叉树;

/**
 * @author XZ
 * @create 2021-06-21 21:29
 * https://leetcode-cn.com/problems/invert-binary-tree/
 */
public class _226_翻转二叉树 {
    public TreeNode invertTree(TreeNode root) {
        //这是前序遍历的方法，中序遍历和后序遍历一样可以。
        if (root==null) return root;

        TreeNode tmp = root.left;
        root.left = root.right;
        root.right=tmp;

        invertTree(root.left);
        invertTree(root.right);
        return root;
    }
}
